package com.beiding.dbrequest.common;

import io.netty.util.internal.SystemPropertyUtil;

import java.nio.charset.Charset;
import java.util.concurrent.atomic.AtomicLong;

/**
 * 公共方法
 *
 * @author 丁常磊
 * @date 2021/7/16 12:18
 */

public class Common {
    public static final Charset CHARSET = Charset.forName("utf8");
    private static AtomicLong ID_LONG = new AtomicLong(Long.MIN_VALUE);

    private static Integer aps;

    public static Long createId() {

        return ID_LONG.addAndGet(1);
    }

    public static int availableProcessors() {
        if (aps == null) {
            aps = Math.max(1, SystemPropertyUtil.getInt(
                    "io.netty.eventLoopThreads", Runtime.getRuntime().availableProcessors() * 2));
        }
        return aps;
    }


}
